// 用户认证相关API接口
import request from './request'
import { API_CONFIG } from '@/config/api'

/**
 * 用户注册
 * @param {Object} userData - 用户注册数据
 * @param {string} userData.username - 用户名
 * @param {string} userData.password - 密码
 * @param {string} userData.confirmPassword - 确认密码
 * @returns {Promise} 注册结果
 */
export const userRegister = (userData) => {
  return request({
    method: 'POST',
    url: API_CONFIG.ENDPOINTS.AUTH.REGISTER,
    data: {
      username: userData.username,
      password: userData.password,
      confirmPassword: userData.confirmPassword
    }
  })
}

/**
 * 用户登录
 * @param {Object} loginData - 登录数据
 * @param {string} loginData.username - 用户名
 * @param {string} loginData.password - 密码
 * @param {boolean} loginData.remember - 是否记住登录状态
 * @returns {Promise} 登录结果
 */
export const userLogin = (loginData) => {
  return request({
    method: 'POST',
    url: API_CONFIG.ENDPOINTS.AUTH.LOGIN,
    data: {
      username: loginData.username,
      password: loginData.password,
      remember: loginData.remember || false
    }
  })
}

/**
 * 用户登出
 * @returns {Promise} 登出结果
 */
export const userLogout = () => {
  return request({
    method: 'POST',
    url: API_CONFIG.ENDPOINTS.AUTH.LOGOUT
  })
}

/**
 * 获取用户信息
 * @returns {Promise} 用户信息
 */
export const getUserInfo = () => {
  return request({
    method: 'GET',
    url: API_CONFIG.ENDPOINTS.AUTH.USER_INFO
  })
}

/**
 * 刷新token
 * @returns {Promise} 新的token
 */
export const refreshToken = () => {
  return request({
    method: 'POST',
    url: API_CONFIG.ENDPOINTS.AUTH.REFRESH_TOKEN
  })
}

/**
 * 修改密码
 * @param {Object} passwordData - 密码数据
 * @param {string} passwordData.oldPassword - 旧密码
 * @param {string} passwordData.newPassword - 新密码
 * @param {string} passwordData.confirmPassword - 确认新密码
 * @returns {Promise} 修改结果
 */
export const changePassword = (passwordData) => {
  return request({
    method: 'POST',
    url: API_CONFIG.ENDPOINTS.AUTH.CHANGE_PASSWORD,
    data: passwordData
  })
}